package com.cloud.demo.login.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.demo.login.bean.dto.LoginByAccountDTO;
import com.cloud.demo.login.bean.dto.QueryAllAccountDTO;
import com.cloud.demo.login.bean.entity.AccountInfo;
import com.cloud.demo.login.dao.AccountInfoMapper;
import com.cloud.demo.login.service.AccountInfoService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 类说明
 *
 * @author szj
 * @date 2021/7/28
 */
@Service
public class AccountInfoServiceImpl extends ServiceImpl<AccountInfoMapper, AccountInfo> implements AccountInfoService {
    @Override
    public void create(LoginByAccountDTO loginByAccountDTO) {
        AccountInfo accountInfo = new AccountInfo();
        accountInfo.setCreateTime(new Date());
        accountInfo.setUpdateTime(new Date());
        accountInfo.setUserId(1);
        accountInfo.setAccountType((byte)2);
        accountInfo.setUserType((byte)0);
        accountInfo.setAccountName(loginByAccountDTO.getAccountName());
        accountInfo.setPassword(loginByAccountDTO.getPassword());
        accountInfo.setIsDelete(false);
        this.save(accountInfo);
    }

    @Override
    public IPage<AccountInfo> queryAll(QueryAllAccountDTO query) {
        IPage<AccountInfo> page = new Page<>();
        page.setCurrent(1);
        page.setSize(10);
        return this.page(page);
    }

    @Override
    public void delete(Integer id) {
        this.removeById(id);
    }

    @Override
    public AccountInfo detail(Integer id) {
        // 使用xml方式，无法触发配置的逻辑删除
//        baseMapper.detailById(id);
        return this.query().eq("id", id).one();
    }
}
